import logging
import sys
import time
import os
from logging.handlers import TimedRotatingFileHandler


def get_logger(log_path, file_name, backup_count=0):
    logger = logging.getLogger(f'{log_path}/{file_name}')
    logger.setLevel(logging.INFO)
    sh = logging.StreamHandler()
    if not os.path.exists(log_path):
        os.makedirs(log_path)
    fh = TimedRotatingFileHandler(
        filename=os.path.join(log_path, file_name),
        when="midnight",
        interval=1,
        backupCount=backup_count,
    )
    formatter = logging.Formatter(
        "%(asctime)s - %(levelname)s - lineno: %(lineno)d -> %(message)s"
    )
    formatter2 = logging.Formatter("%(asctime)s - %(levelname)s -> %(message)s")
    sh.setFormatter(formatter)
    fh.setFormatter(formatter)
    logger.addHandler(sh)
    logger.addHandler(fh)
    return logger